﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
/// <summary>
/// Summary description for Data
/// </summary>
public class Data
{
	public Data()
	{

        ketNoi();//
		// TODO: Add constructor logic here
		//
	}

    public OleDbConnection con;
    public OleDbDataReader rd;
    
    public void ketNoi()
    {
        con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\DeTai_CuoiKy_ThuongMaiDienTu\App_Data\data_dtdd.mdb;");
        con.Open();
    }

    public OleDbDataReader getData(string query)
    {

        OleDbCommand cmd = new OleDbCommand(query, con);
        return cmd.ExecuteReader();
    }

    public int insertData(string query)
    {
        OleDbCommand cmd = new OleDbCommand(query, con);
        return cmd.ExecuteNonQuery();
    }

    public int run(string query)
    {
        OleDbCommand cmd = new OleDbCommand(query, con);
        return cmd.ExecuteNonQuery();
    }


    public void dongKetNoi()
    {
        if (con.State != ConnectionState.Closed)
        {
            con.Close();
            con.Dispose();
        }
    }

    public OleDbDataReader maxID(string tenBang, string ID)
    {
        string query = "SELECT MAX (" + ID + ") FROM " + tenBang;
        return getData(query);
    }
}
